package com.yalu.util; 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* @ClassName: FileUtil
* @Description: 文件操作工具类
* @date 2013-10-28 下午08:55:24
* @author zch
*
*/
public class FileUtil {
	public static File saveFile(String savePath, File excelFile,
			String excelFileFileName) {
		InputStream is = null;
		OutputStream os = null;
		File returnFile = null;
		File dir = new File(savePath);
		if(!dir.exists()){
			dir.mkdirs();
		}
		String saveFilePath = savePath + "\\" +BaseUtil.getNow()+"_"+ excelFileFileName;
		
		try {
			is = new FileInputStream(excelFile);
		os = new FileOutputStream(saveFilePath);
		byte[] buffer = new byte[2875623];
		int length = 0;
		while (-1 != (length = is.read(buffer))) {
			os.write(buffer, 0, length);
		}
		returnFile = new File(saveFilePath);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(is!=null){
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(os!=null){
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return returnFile;}

	public static void deleteFile(File file) {
		if(file.exists()){
			file.delete();
		}
	}
}
 